package com.lei.app.controller.socket.web;

import com.lei.app.handler.DbRoomWsHandler;
import com.lei.app.handler.WsHandler;
import com.lei.app.provider.DbRoomProvider;
import com.lei.app.provider.WsRoomProvider;
import com.lei.app.websocket.AbstractWsEndpoint;
import com.lei.app.websocket.NutIocWebSocketConfigurator;
import lombok.extern.slf4j.Slf4j;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import javax.websocket.EndpointConfig;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

/**
 * @author 郑兴泉 956607644@qq.com
 * @data 2020/4/9
 * 描述：
 */
@ServerEndpoint(value = "/db/room", configurator = NutIocWebSocketConfigurator.class)
@IocBean
@Slf4j
public class WebSocketDbRooms extends AbstractWsEndpoint {

    @Inject
    private Dao dao;


    @Override
    public WsHandler createHandler(Session session, EndpointConfig config) {
        DbRoomWsHandler dbRoom =   new DbRoomWsHandler();
        dbRoom.setDao(dao);
        dbRoom.setRoomProvider(new DbRoomProvider());
        dbRoom.setEndpoint(this);
        return dbRoom;
    }

    @Override
    public void setRoomProvider(WsRoomProvider roomProvider) {
        super.setRoomProvider(new DbRoomProvider());
    }
}
